/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:31
*/
KISSY.add("tabs/bar-render",["toolbar"],function(c,b){return b("toolbar").getDefaultRender().extend({beforeCreateDom:function(a){a.elAttrs.role="tablist"}},{name:"TabsBarRender"})});
KISSY.add("tabs/bar",["toolbar","./bar-render"],function(c,b){var a=b("toolbar"),d=b("./bar-render"),a=a.extend({bindUI:function(){var a=this;a.on("afterSelectedChange",function(b){b.newVal&&b.target.isTabsTab&&a.set("selectedTab",b.target)})},syncUI:function(){var a=this,b=a.get("children");c.each(b,function(b){if(b.get("selected"))return a.setInternal("selectedTab",b),!1})},handleKeyDownInternal:function(a){var b=this.get("selectedTab"),a=this.getNextItemByKeyDown(a,b);if("boolean"===typeof a)return a;
a.set("selected",!0);return!0},_onSetSelectedTab:function(a,b){var d;a&&(b&&(d=b.prevVal)&&d.set("selected",!1),a.set("selected",!0))},_onSetHighlightedItem:function(a,b){this.callSuper(a,b);"mouse"===this.get("changeType")&&this._onSetSelectedTab.apply(this,arguments)}},{ATTRS:{selectedTab:{},changeType:{value:"click"},defaultChildCfg:{value:{xclass:"tabs-tab"}},xrender:{value:d}},xclass:"tabs-bar"});a.ChangeType={CLICK:"click",MOUSE:"mouse"};return a});
KISSY.add("tabs/body",["component/container"],function(c,b){function a(a,b,c){if(a.get("lazyRender")){var e=a.get("children")[c];if(!e.get("selected"))return e}return d.superclass[b].call(a,c)}var d=b("component/container").extend({bindUI:function(){var a=this;a.on("afterSelectedPanelIndexChange",function(b){var d=a.get("children"),c=b.newVal,i;d[c]&&((i=d[b.prevVal])&&i.set("selected",!1),a.selectPanelByIndex(c))})},syncUI:function(){var a=this,b=a.get("children");c.each(b,function(b,d){if(b.get("selected"))return a.set("selectedPanelIndex",
d),!1})},createChild:function(b){return a(this,"createChild",b)},renderChild:function(b){return a(this,"renderChild",b)},selectPanelByIndex:function(a){this.get("children")[a].set("selected",!0);this.get("lazyRender")&&this.renderChild(a)}},{ATTRS:{selectedPanelIndex:{},allowTextSelection:{value:!0},focusable:{value:!1},lazyRender:{},handleMouseEvents:{value:!1},defaultChildCfg:{value:{xclass:"tabs-panel"}}},xclass:"tabs-body"});return d});
KISSY.add("tabs/tab-render",["button"],function(c,b){return b("button").getDefaultRender().extend({beforeCreateDom:function(a){var b=a.elAttrs;b.role="tab";a.selected&&(b["aria-selected"]=!0,a.elCls.push(this.getBaseCssClasses("selected")))},_onSetSelected:function(a){var b=this.$el,c=this.getBaseCssClasses("selected");b[a?"addClass":"removeClass"](c).attr("aria-selected",!!a)}},{name:"TabsTabRender",HTML_PARSER:{selected:function(a){return a.hasClass(this.getBaseCssClass("selected"))}}})});
KISSY.add("tabs/tab",["button","./tab-render"],function(c,b){var a=b("button"),d=b("./tab-render");return a.extend({isTabsTab:!0,bindUI:function(){this.on("click",function(){this.set("selected",!0)})}},{ATTRS:{handleMouseEvents:{value:!1},focusable:{value:!1},selected:{view:1},xrender:{value:d}},xclass:"tabs-tab"})});
KISSY.add("tabs/panel-render",["component/container"],function(c,b){return b("component/container").getDefaultRender().extend({beforeCreateDom:function(a){a.elAttrs.role="tabpanel";a.selected?a.elCls.push(this.getBaseCssClasses("selected")):a.elAttrs["aria-hidden"]=!1},_onSetSelected:function(a){var b=this.$el,c=this.getBaseCssClasses("selected");b[a?"addClass":"removeClass"](c).attr("aria-hidden",!a)}},{name:"TabsPanelRender",HTML_PARSER:{selected:function(a){return a.hasClass(this.getBaseCssClass("selected"))}}})});
KISSY.add("tabs/panel",["component/container","./panel-render"],function(c,b){var a=b("component/container"),d=b("./panel-render");return a.extend({isTabsPanel:1},{ATTRS:{selected:{view:1},focusable:{value:!1},allowTextSelection:{value:!0},xrender:{value:d}},xclass:"tabs-panel"})});
KISSY.add("tabs/render",["component/container"],function(c,b){return b("component/container").getDefaultRender().extend({beforeCreateDom:function(a){a.elCls.push(this.getBaseCssClass(this.control.get("barOrientation")))},decorateDom:function(){var a=this.control;a.get("bar").set("changeType",a.get("changeType"))},_onSetBarOrientation:function(a){this.$el.removeClass(this.getBaseCssClass("top bottom left right")).addClass(this.getBaseCssClass(a))}},{name:"TabsRender",HTML_PARSER:{barOrientation:function(a){return(a=
a[0].className.match(/(top|bottom|left|right)\b/))&&a[1]||"top"}}})});
KISSY.add("tabs","component/container,tabs/bar,tabs/body,tabs/tab,tabs/panel,tabs/render".split(","),function(c,b){var a=b("component/container"),d=b("tabs/bar"),l=b("tabs/body");b("tabs/tab");var m=b("tabs/panel"),n=b("tabs/render"),a=a.extend({initializer:function(){var a=this.get("items");if(a){var b=this.get("children"),j=this.get("barOrientation"),d,f=this.get("prefixCls"),g={prefixCls:f,xclass:"tabs-bar",changeType:this.get("changeType"),children:[]},f={prefixCls:f,xclass:"tabs-body",lazyRender:this.get("lazyRender"),
children:[]},h=g.children,k=f.children;c.each(a,function(a){d=d||a.selected;h.push({content:a.title,selected:a.selected});k.push({content:a.content,selected:a.selected})});if(!d&&h.length){h[0].selected=true;k[0].selected=true}b[e[j]]=g;b[1-e[j]]=f}},addItem:function(a,b){var c=this.get("bar"),d,f,g=c.get("children"),e=this.get("body");if(typeof b==="undefined")b=g.length;d={content:a.title};f={content:a.content};c.addChild(d,b);d=g[b];e.addChild(f,b);if(a.selected){c.set("selectedTab",d);e.set("selectedPanelIndex",
b)}return this},removeItemAt:function(a,b){var c=this.get("bar"),d=c.get("children"),e=c.getChildAt(a),g=this.get("body");e.get("selected")&&(d.length===1?c.set("selectedTab",null):a===0?c.set("selectedTab",c.getChildAt(a+1)):c.set("selectedTab",c.getChildAt(a-1)));c.removeChild(c.getChildAt(a),b);g.removeChild(g.getChildAt(a),b);return this},removeItemByTab:function(a,b){return this.removeItemAt(c.indexOf(a,this.get("bar").get("children")),b)},removeItemByPanel:function(a,b){return this.removeItemAt(c.indexOf(a,
this.get("body").get("children")),b)},getSelectedTab:function(){var a=this.get("bar"),b=null;c.each(a.get("children"),function(a){if(a.get("selected")){b=a;return false}});return b},getSelectedPanel:function(){var a=this.get("body"),b=null;c.each(a.get("children"),function(a){if(a.get("selected")){b=a;return false}});return b},getTabs:function(){return this.get("bar").get("children")},getPanels:function(){return this.get("body").get("children")},getTabAt:function(a){return this.get("bar").get("children")[a]},
getPanelAt:function(a){return this.get("body").get("children")[a]},setSelectedTab:function(a){var b=this.get("bar"),d=this.get("body");b.set("selectedTab",a);d.set("selectedPanelIndex",c.indexOf(a,b.get("children")));return this},setSelectedPanel:function(a){var b=this.get("bar"),d=this.get("body"),a=c.indexOf(a,d.get("children"));d.set("selectedPanelIndex",a);b.set("selectedTab",this.getTabAt(a));return this},bindUI:function(){this.on("afterSelectedTabChange",function(a){this.setSelectedTab(a.newVal)})}},
{ATTRS:{items:{},changeType:{},lazyRender:{value:false},handleMouseEvents:{value:false},allowTextSelection:{value:true},focusable:{value:false},bar:{getter:function(){return this.get("children")[e[this.get("barOrientation")]]}},body:{getter:function(){return this.get("children")[1-e[this.get("barOrientation")]]}},barOrientation:{view:1,value:"top"},xrender:{value:n}},xclass:"tabs"});a.Orientation={TOP:"top",BOTTOM:"bottom",LEFT:"left",RIGHT:"right"};var e={top:0,left:0,bottom:1,right:0};a.ChangeType=
d.ChangeType;a.Bar=d;a.Body=l;a.Panel=m;return a});
